<template>
    <view class="merchant_backend">
        <view class="merchant_bg"></view>
        <view class="merchant_nav">
            <p>Total</p>
            <view class="money">
                {{ info.total_income || "0.00" }}
            </view>
            <view class="nav_bottom row">
                <text>Today {{ info.today_income || "0.00" }}</text>
                <view
                    class="row nav-right"
                    @click.stop="handleRoute('./income')"
                >
                    <text style="margin-top: -6rpx">Income Ledge</text>
                    <u-icon
                        name="arrow-right"
                        color="#999999"
                        size="15"
                    ></u-icon>
                </view>
            </view>
        </view>
        <view class="merchant_card">
            <p>Management</p>
            <ul class="row">
                <li @click.stop="handleRoute('./menu')">
                    <image
                        src="@/static/menu/menu_04.png"
                        mode="aspectFit"
                    ></image>
                    <p>Create menu</p>
                </li>
                <li @click.stop="handleRoute('./orders')">
                    <image
                        src="@/static/menu/menu_05.png"
                        mode="aspectFit"
                    ></image>
                    <p>Order</p>
                </li>
                <li>
                    <image
                        src="@/static/menu/menu_06.png"
                        mode="aspectFit"
                    ></image>
                    <p>Promotion</p>
                </li>

                <li @click.stop="handleRoute('/pages/user/bank/bankAccount')">
                    <image
                        src="@/static/menu/menu_01.png"
                        mode="aspectFit"
                    ></image>
                    <p>Bank Card</p>
                </li>
                <li @click.stop="handleRoute('./wallet')">
                    <image
                        src="@/static/menu/menu_02.png"
                        mode="aspectFit"
                    ></image>
                    <p>E-wallet</p>
                </li>

                <li @click.stop="handleRoute('./assistant')" class="bg">
                    <image
                        src="@/static/menu/menu_07.png"
                        mode="aspectFit"
                    ></image>
                    <p>assistant</p>
                </li>
                <li
                    @click.stop="handleRoute('/pages/user/seller_apply')"
                    class="bg"
                >
                    <image
                        src="@/static/menu/menu_08.png"
                        mode="aspectFit"
                    ></image>
                    <p>Modify <br />information</p>
                </li>
            </ul>
        </view>
    </view>
</template>

<script>
import { myShopData } from "@/lib/service.js";
import { getVerification } from "@/lib/business.js";
import jzH5ScanCode from "@/uni_modules/jz-h5-scanCode/js/index.js";
export default {
    data() {
        return {
            info: {
                total_income: "",
                today_income: "",
            },
        };
    },
    onLoad() {
        const pluginInfo = jzH5ScanCode.getPluginInfo();
        console.log("插件信息:", pluginInfo);
    },
    onShow() {
        this.handleInfo();
    },
    methods: {
        onNavigationBarButtonTap(e) {
            console.log("点击事件", e);
            let _this = this;
            // #ifdef H5
            try {
                jzH5ScanCode.scanCode({
                    success: (res1) => {
                        _this.handleBarCodeNumber(res1.result);
                        console.log("扫码成功:", res1.result);
                    },
                    fail: (res) => {
                        console.log("扫码失败:", res.errMsg);
                    },
                });
            } catch (error) {
                console.error("启动扫码失败:", error);
                uni.showToast({
                    title: "启动扫码失败",
                    icon: "none",
                });
            }

            // #endif
            // #ifdef APP-PLUS
            uni.scanCode({
                onlyFromCamera: true,
                // scanType: ["barCode"],
                success: (res) => {
                    _this.handleBarCodeNumber(res.result);
                },
                fail: (err) => {
                    // vibrateSuccess();
                    // 扫码失败回调
                    console.error("扫码失败: ", err);
                },
            });
            // #endif
        },
        isGoodsBarcode(barcode) {
            return barcode.length > 10; // 假设商品条形码长度大于10
        },
        handleBarCodeNumber(orderno) {
            let _this = this;
            const parts = orderno.split(" ", 2); // 第二个参数限制分割次数
            const code = parts[0];
            const order = parts[1] || ""; // 防止没有 's' 的情况
            uni.showModal({
                title: "Prompt",
                content: "Are you sure you want to write off？",
                success: async (res) => {
                    if (res.confirm) {
                        getVerification({
                            orderno: order,
                            verification_code: code,
                        })
                            .then((res) => {
                                if (res.statusCode == 0) {
                                    uni.showToast({
                                        title: "success",
                                        icon: "none",
                                    });
                                    // _this.handleInfo();
                                } else {
                                    uni.showToast({
                                        title: res.message,
                                        icon: "none",
                                    });
                                }
                            })
                            .catch((res) => {});
                    }
                },
            });
        },
        handleInfo() {
            myShopData()
                .then((res) => {
                    if (res.statusCode == 0) {
                        this.info = res.data;
                    }
                })
                .catch((res) => {});
        },
        handleRoute(url) {
            uni.navigateTo({
                url,
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.merchant_bg {
    width: 100%;
    height: 240rpx;
    background: #fc721a;
    border-radius: 0rpx 0rpx 80rpx 80rpx;
}

.merchant_nav {
    margin: 0 28rpx;
    height: 222.82rpx;
    background: linear-gradient(107.08deg, #ffc29b 6.44%, #ffe8d5 92.03%);
    border-radius: 22rpx;
    margin-top: -160rpx;
    padding: 28rpx 34rpx;

    p {
        font-family: PingFang SC;
        font-weight: 500;
        color: #272727;
        font-size: 30rpx;
    }

    .money {
        font-family: PingFang SC;
        font-weight: 500;
        color: #000000;
        font-size: 52rpx;
        margin-top: 20rpx;
    }

    .nav_bottom {
        margin-top: 24rpx;
        justify-content: space-between;

        > text {
            font-family: PingFang SC;
            font-weight: 500;
            color: #272727;
            font-size: 36rpx;
        }

        .nav-right {
            text {
                font-family: PingFang SC;
                font-weight: 500;
                color: #999999;
                font-size: 24rpx;
            }
            .rightIcon {
                z-index: 99999;
            }
        }
    }
}

.merchant_card {
    margin: 0 28rpx;
    margin-top: 34rpx;
    //height: 600rpx;
    background: #ffffff;
    border-radius: 22rpx;
    box-shadow: 0rpx 0rpx 19.08rpx rgba(239, 239, 239, 0.79);
    padding: 36rpx 24rpx;

    p {
        font-family: PingFang SC;
        font-weight: 500;
        color: #272727;
        font-size: 30rpx;
    }

    ul {
        justify-content: space-between;
        flex-wrap: wrap;

        li {
            width: 33%;
            margin-top: 58rpx;
            text-align: center;

            image {
                width: 130rpx;
                height: 130rpx;
                border-radius: 50%;
            }

            p {
                font-family: PingFang SC;
                font-weight: 500;
                color: #666666;
                font-size: 24rpx;
                padding-top: 8rpx;
            }
        }
        .bg {
            image {
                width: 130rpx;
                height: 130rpx;
                background: #f4ede3;
                border-radius: 50%;
                padding: 12rpx;
                box-sizing: border-box;
            }
        }
    }
}
</style>
